(function(window){
	var Subject_moni_infoCtrl = {
		data:{},
		init: function(data){
			this.bindEven();
			var h=$(window).height()-40-80;
			$(".box_q_type").height(h);
			$(".box_questions_2").height(h);
			$(".box_questions").height(h);
			$("#q_type_1 li").eq("1").addClass("done");
			$("#q_type_1 li").eq("3").addClass("half_done");
			$(".sumbit_answer").parent().hide();
			Subject_moni_infoCtrl.data=data;
			
        },
		pev_questions:function(){
			var _this=$(".all_questions:visible");
			var qid= _this.attr("data-qid");
			var pev_qid=$(_this).prev(".all_questions");
			Subject_moni_infoCtrl.has_done(qid);
			if(pev_qid.length>0){
				var qid=pev_qid.attr("data-qid");
				Subject_moni_infoCtrl.show_questions(qid);
			//	_this.hide();
			//	pev_qid.show();
			}else{
				dialog("当前为第一题");	
			}
			 
		},
		
		next_questions:function(){
			var _this=$(".all_questions:visible");
			var qid= _this.attr("data-qid");
			var pev_qid=$(_this).next(".all_questions");
			Subject_moni_infoCtrl.has_done(qid);
			if(pev_qid.length>0){
				var qid=pev_qid.attr("data-qid");
				Subject_moni_infoCtrl.show_questions(qid);
			}else{
				dialog("当前为最后第一题");
				//hiApp.confirm("");	
			}
			Subject_moni_infoCtrl.count_remark();
		},
		collect_questions:function(){
			var _this=$(".all_questions:visible");
			var qid= _this.attr("data-qid");
			var examid=Subject_moni_infoCtrl.data.query.examid;
			hiApp.showIndicator();
			$.get("/User/collect_questions",{qid:qid,exams_id:examid},function(data){
				hiApp.hideIndicator();
				if(data>0){
					dialog("收藏成功");
				}else{
					dialog("系统错误，收藏失败");
				}
			})
		},
		has_done:function(qid){
			var _this=$("[data-id='all_questions_"+qid+"']");
			var answer=_this.find("dd .checked").length;
			var all_q=$(".q_table li").length;
			if(answer>0){
				$("[data-li-qid="+qid+"]").removeClass(".half_done").addClass("done");
			}
			var done=$(".q_table .done").length;
		   $("#box_questions_done").text(done);
		   $("#box_questions_new").text(Number(all_q)-Number(done));
		},
		
		count_remark:function(){
			$("#box_questions_remark").text($(".q_table .half_done").length);
		},
		remark_questions:function(){
			var _this=$(".all_questions:visible");
			var qid= _this.attr("data-qid");
			$("[data-li-qid="+qid+"]").addClass("half_done");
			Subject_moni_infoCtrl.count_remark();
		},
		show_questions:function(qid){
			$(".q_type .q_table li").removeClass("doing");
			$("[data-li-qid="+qid+"]").addClass("doing");
			$(".all_questions").hide();
			$("[data-id='all_questions_"+qid+"']").show();
		},
		show_questions_li:function(){
			var qid=$(this).attr("data-li-qid");
			Subject_moni_infoCtrl.show_questions(qid);
		},
		bindEven: function(){
				var bindings = [{
					element:'#pev_questions',
					event: hiApp.device.click,
					handler: this.pev_questions
				},{
					element:'#next_questions',
					event: hiApp.device.click,
					handler: this.next_questions
				},{
					element:'#remark_questions',
					event: hiApp.device.click,
					handler: this.remark_questions
				},{
					element:'.q_type .q_table li',
					event: hiApp.device.click,
					handler: this.show_questions_li
				},
				{
					element:'#collect_questions',
					event: hiApp.device.click,
					handler: this.collect_questions
				}
			];
            bindEvents(bindings);
        },
		 
		
    };
		
	window.BoxEdu_Subject_moni_infoCtrl = Subject_moni_infoCtrl;
						
})(window);